<script setup>
import { ref } from 'vue'
import MarketShareChart from './components/MarketShareChart.vue'
import ProcurementAnalysisChart from './components/ProcurementAnalysisChart.vue'
import FpsAnalysisChart from './components/FpsAnalysisChart.vue'
import CpvAnalysisChart from './components/CpvAnalysisChart.vue'
import ManufacturingAnalysisChart from './components/ManufacturingAnalysisChart.vue'
import InventoryAnalysisChart from './components/InventoryAnalysisChart.vue'
import PtvAnalysisChart from './components/PtvAnalysisChart.vue'
import BackendAnalytics from './components/BackendAnalytics.vue'

// 当前显示的视图
const currentView = ref('dashboard')

// 切换视图
function switchView(view) {
    currentView.value = view
}

// 返回仪表盘
function goBackToDashboard() {
    currentView.value = 'dashboard'
}
</script>

<template>
	<video id="video-background" autoplay muted loop playsinline>
		<source src="./assets/bg.mp4" type="video/mp4" />
	</video>
	
	<!-- 仪表盘视图 -->
	<div v-if="currentView === 'dashboard'" class="dashboard-container">
		<h1 class="dashboard-title">企业运营数据分析平台 <button class="ai-analysis-btn" @click="switchView('ai-analytics')">🤖 AI自助分析</button></h1>
		<div class="charts-container">
			<section>
				<div class="fpv-chart chart">
					<PtvAnalysisChart />
					<div class="j1"></div>
					<div class="j4"></div>
				</div>
				<div class="cpv-chart chart">
					<FpsAnalysisChart />
					<div class="j1"></div>
					<div class="j4"></div>
				</div>
			</section>
			<section>
				<div class="manufact-chart chart">
					<ManufacturingAnalysisChart />
					<div class="j1"></div>
					<div class="j4"></div>
				</div>
			</section>
			<section>
				<div class="inventory-chart chart">
					<InventoryAnalysisChart />
					<div class="j1"></div>
					<div class="j4"></div>
				</div>
				<div class="ptv-chart chart">
					<CpvAnalysisChart />
					<div class="j1"></div>
					<div class="j4"></div>
				</div>
			</section>
		</div>
		<div class="charts-container">
			<section>
				<div class="market-chart chart">
					<MarketShareChart />
					<div class="j1"></div>
					<div class="j4"></div>
				</div>
			</section>
			<section>
				<div class="procurement-chart chart">
					<ProcurementAnalysisChart />
					<div class="j1"></div>
					<div class="j4"></div>
				</div>
			</section>
		</div>
	</div>

	<!-- AI自助分析视图 -->
	<div v-else-if="currentView === 'ai-analytics'" class="ai-analytics-page">
		<header class="common-header">
			<h1 class="page-title">企业运营数据自助分析平台</h1>
			<button class="action-btn back-btn" @click="goBackToDashboard">
				<span class="btn-icon">←</span> 返回仪表盘
			</button>
		</header>
		<BackendAnalytics />
	</div>
</template>

<style scoped>
/* 视频容器样式 */
#video-background {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	z-index: -1; /* 确保视频在内容下方 */
	object-fit: cover; /* 覆盖整个区域 */
}

/* AI自助分析按钮样式 */
.ai-analysis-btn {
	position: absolute;
	top: 25px;
	right: 40px;
	padding: 10px 20px;
	background: linear-gradient(45deg, #0760c5, #32f08c);
	color: white;
	border: none;
	border-radius: 25px;
	font-size: 16px;
	font-weight: bold;
	cursor: pointer;
	transition: all 0.3s ease;
	box-shadow: 0 4px 15px rgba(50, 240, 140, 0.3);
}

.ai-analysis-btn:hover {
	transform: translateY(-2px);
	box-shadow: 0 6px 20px rgba(50, 240, 140, 0.4);
}

.ai-analysis-btn:active {
	transform: translateY(0);
}

/* AI分析页面样式 */
.ai-analytics-page {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	color: white;
	overflow-y: auto;
}

.ai-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 25px 40px;
	background: rgba(0, 0, 0, 0.8);
	backdrop-filter: blur(10px);
	border-bottom: 1px solid rgba(7, 96, 197, 0.3);
	position: sticky;
	top: 0;
	z-index: 100;
}

.page-title {
	font-size: 24px;
	color: #32f08c;
	margin: 0;
}

.back-btn {
	padding: 10px 20px;
	background: rgba(7, 96, 197, 0.3);
	color: white;
	border: 1px solid rgba(7, 96, 197, 0.5);
	border-radius: 8px;
	font-size: 16px;
	cursor: pointer;
	transition: all 0.3s ease;
}

.back-btn:hover {
	background: rgba(7, 96, 197, 0.5);
	transform: translateY(-1px);
}

/* 内容层样式（在视频上方显示） */
.dashboard-container {
	position: absolute;
	color: white;
	text-align: center;
	box-sizing: border-box;
	width: 99.9%;
}

/* 标题 */
.dashboard-title {
	position: relative;
	width: 100%;
	height: 87px;
	background: linear-gradient(135deg, rgba(0, 15, 30, 0.9), rgba(7, 96, 197, 0.8));
	background-image: linear-gradient(135deg, rgba(0, 15, 30, 0.9), rgba(7, 96, 197, 0.8)), url('@/assets/title_bg.png');
	background-blend-mode: overlay;
	background-size: cover;
	color: white;
	text-align: center;
	padding-top: 20px;
	border-bottom: 2px solid rgba(50, 240, 140, 0.3);
	box-shadow: 0 4px 20px rgba(7, 96, 197, 0.2);
}

/* 通用头部样式 */
.common-header {
	width: 100%;
	height: 87px;
	background: linear-gradient(135deg, rgba(0, 15, 30, 0.9), rgba(7, 96, 197, 0.8));
	background-blend-mode: overlay;
	background-size: cover;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0 40px;
	border-bottom: 2px solid rgba(50, 240, 140, 0.3);
	box-shadow: 0 4px 20px rgba(7, 96, 197, 0.2);
	position: relative;
	z-index: 100;
}

.page-title {
	color: white;
	font-size: 24px;
	font-weight: bold;
	margin: 0;
	text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
	position: relative;
	transition: all 0.3s ease;
}

.page-title::after {
	content: '';
	position: absolute;
	bottom: -5px;
	left: 0;
	width: 60px;
	height: 3px;
	background: linear-gradient(90deg, #32f08c, transparent);
	border-radius: 3px;
}

/* 统一按钮样式 */
.action-btn {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 20px;
	border: none;
	border-radius: 25px;
	font-size: 16px;
	font-weight: 600;
	cursor: pointer;
	transition: all 0.3s ease;
	text-decoration: none;
	box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
	backdrop-filter: blur(5px);
}

.ai-analysis-btn {
	position: absolute;
	top: 50%;
	right: 40px;
	transform: translateY(-50%);
	background: linear-gradient(45deg, #0760c5, #32f08c);
	color: white;
}

.ai-analysis-btn:hover {
	transform: translateY(-50%) translateY(-2px);
	box-shadow: 0 6px 20px rgba(50, 240, 140, 0.4);
}

.back-btn {
	background: rgba(0, 15, 30, 0.8);
	color: #32f08c;
	border: 1px solid rgba(50, 240, 140, 0.3);
}

.back-btn:hover {
	background: rgba(0, 15, 30, 1);
	border-color: #32f08c;
	box-shadow: 0 4px 15px rgba(50, 240, 140, 0.2);
	transform: translateY(-2px);
}

.btn-icon {
	font-size: 18px;
	font-weight: bold;
}

/* 响应式调整 */
@media (max-width: 768px) {
	.dashboard-title {
		height: auto;
		padding: 20px 15px;
		padding-bottom: 60px;
	}
	
	.common-header {
		height: auto;
		padding: 20px 15px;
		flex-direction: column;
		gap: 15px;
	}
	
	.action-btn {
		position: static !important;
		transform: none !important;
		width: 100%;
		justify-content: center;
		margin-top: 10px;
	}
	
	.page-title {
		font-size: 20px;
		text-align: center;
	}
	
	.page-title::after {
		left: 50%;
		transform: translateX(-50%);
	}
}
.dashboard-title a {
	position: absolute;
	top: 25px;
	right: 40px;
	color: #32f08c;
	text-decoration: none;
	font-size: 20px;
}

/* 图表容器 */
.charts-container {
	display: flex;
}
.charts-container > section {
	flex: 1;
}
.charts-container .chart {
	border: 3px solid transparent;
	border-radius: 8px;
	width: 100%;
	height: 288px;
	box-shadow: 15px 15px 20px #0760c5 inset, -15px -15px 20px #0760c5 inset;
	position: relative;
}

.charts-container .manufact-chart {
	height: 100%;
}

.chart .j1,
.chart .j2,
.chart .j3,
.chart .j4 {
	width: 50px;
	height: 20px;
	border: 3px solid white;
	border-radius: 3px;
	position: absolute;
}

.charts-container .chart .j1 {
	border-right: 0;
	border-bottom: 0;
	top: 0;
	left: 0;
}
.charts-container .chart .j4 {
	border-left: 0;
	border-top: 0;
	right: 0;
	bottom: 0;
}
</style>
